package com.osce.face.controller;

import com.csce.domain.entity.face.FaceRecord;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.face.IFaceRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 人脸识别记录Controller
 *
 * @author zzx
 * @since 2023-11-21
 */
@RestController
@RequestMapping("/face/face_record")
public class FaceRecordController extends BaseController {

    @Resource
    private IFaceRecordService faceRecordService;

    /**
     * 查询人脸识别记录列表
     */
    @PreAuthorize("@ss.hasPermi('face:face_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(@Validated FaceRecord faceRecord) {
        startPage();
        List<FaceRecord> list = faceRecordService.selectFaceRecordList(faceRecord);
        return getDataTable(list);
    }

    /**
     * 导出人脸识别记录列表
     */
    @PreAuthorize("@ss.hasPermi('face:face_record:export')")
    @Log(title = "人脸识别记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaceRecord faceRecord) {
        List<FaceRecord> list = faceRecordService.selectFaceRecordList(faceRecord);
        ExcelUtil<FaceRecord> util = new ExcelUtil<FaceRecord>(FaceRecord.class);
        util.exportExcel(response, list, "人脸识别记录数据");
    }

    /**
     * 获取人脸识别记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('face:face_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(faceRecordService.selectFaceRecordById(id));
    }

    /**
     * 新增人脸识别记录
     */
    @PreAuthorize("@ss.hasPermi('face:face_record:add')")
    @Log(title = "人脸识别记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaceRecord faceRecord) {
        return toAjax(faceRecordService.insertFaceRecord(faceRecord));
    }

    /**
     * 修改人脸识别记录
     */
    @PreAuthorize("@ss.hasPermi('face:face_record:edit')")
    @Log(title = "人脸识别记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaceRecord faceRecord) {
        return toAjax(faceRecordService.updateFaceRecord(faceRecord));
    }

    /**
     * 删除人脸识别记录
     */
    @PreAuthorize("@ss.hasPermi('face:face_record:remove')")
    @Log(title = "人脸识别记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(faceRecordService.deleteFaceRecordByIds(ids));
    }
}
